const {Sequelize} = require('sequelize');
const onLoadedEventList = [];

const sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: __dirname + '/sqlite.db'
});

(async () => {
    try {
        await sequelize.authenticate();
        console.log('Connection has been established successfully.');
        require('./models/inddx'); // load model
        await sequelize.sync({force: false});
        console.log("所有模型均已同步");
        onLoadedEventList.forEach(cb => cb());
    } catch (error) {
        console.error('Unable to connect to the database:', error);
    }
})();

sequelize.onload = cb => onLoadedEventList.push(cb);

module.exports = sequelize;


